11. Exercise: Items and ViewHolders

Quiz: Add RecyclerView Item and ViewHolder

Adding Items to RecyclerView

In this Exercise, you will get to add view items to the recyclerview and use view holders to cache them.

Exercise Code

Exercise:T03.02-Exercise-ViewHolder

Add RecyclerView Item and ViewHolder

You saw me do it, but now it's your turn. Complete the TODOs. Here's a summary:

SOLUTION:
  • Create a layout resource called number_list_item.
  • Make the root layout a FrameLayout
  • Add a TextView to the FrameLayout with an ID and the recommended attributes
  • Open GreenAdapter.java:
  • Create the NumberViewHolder inner class.
  • Set the listItemNumber view TextView variable in the constructor
  • Add the bind helper function.